package com.ruoyi.web.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.bo.PResumeBo;
import com.ruoyi.system.domain.vo.PResumeVo;
import com.ruoyi.system.service.IPResumeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 咨询师个人简历Controller
 *
 * @author ruoyi
 * @date 2022-07-21
 */
@Validated
@Api(value = "咨询师个人简历控制器", tags = {"咨询师个人简历管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/resume")
public class PResumeController extends BaseController {

    private final IPResumeService iPResumeService;

    /**
     * 查询咨询师个人简历列表
     */
    @ApiOperation("查询咨询师个人简历列表")
    @SaCheckPermission("system:resume:list")
    @GetMapping("/list")
    public TableDataInfo<PResumeVo> list(PResumeBo bo, PageQuery pageQuery) {
        return iPResumeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出咨询师个人简历列表
     */
    @ApiOperation("导出咨询师个人简历列表")
    @SaCheckPermission("system:resume:export")
    @Log(title = "咨询师个人简历", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PResumeBo bo, HttpServletResponse response) {
        List<PResumeVo> list = iPResumeService.queryList(bo);
        ExcelUtil.exportExcel(list, "咨询师个人简历", PResumeVo.class, response);
    }

    /**
     * 获取咨询师个人简历详细信息
     */
    @ApiOperation("获取咨询师个人简历详细信息")
    @SaCheckPermission("system:resume:query")
    @GetMapping("/{id}")
    public R<PResumeVo> getInfo(@ApiParam("主键")
                                     @NotNull(message = "主键不能为空")
                                     @PathVariable("id") Long id) {
        return R.ok(iPResumeService.queryById(id));
    }

    /**
     * 新增咨询师个人简历
     */
    @ApiOperation("新增咨询师个人简历")
    @SaCheckPermission("system:resume:add")
    @Log(title = "咨询师个人简历", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PResumeBo bo) {
        return toAjax(iPResumeService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改咨询师个人简历
     */
    @ApiOperation("修改咨询师个人简历")
    @SaCheckPermission("system:resume:edit")
    @Log(title = "咨询师个人简历", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PResumeBo bo) {
        return toAjax(iPResumeService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除咨询师个人简历
     */
    @ApiOperation("删除咨询师个人简历")
    @SaCheckPermission("system:resume:remove")
    @Log(title = "咨询师个人简历", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iPResumeService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }

    @ApiModelProperty("审核咨询师")
    @SaCheckPermission("system:resume:add")
    @Log(title = "咨询师个人简历", businessType = BusinessType.UPDATE)
    @PutMapping("approve")
    public R<Void> approve(@RequestBody PResumeBo bo) {
        return toAjax(iPResumeService.approve(bo.getUserId(), bo.getIsFlag()) ? 1 : 0);
    }

}
